<template>
  <div>
    <!-- 全国A级旅游景区个数和接待人次 -->
    <Echart :options="options" id="total-chart" height="290px" width="100%">
    </Echart>
  </div>
</template>

<script>
import Echart from "@/common/echart";
export default {
  data() {
    return {
      options: {},
    };
  },
  components: {
    Echart,
  },
  props: {
    cdata: {
      type: Object,
      default: () => ({}),
    },
  },
  watch: {
    cdata: {
      handler(newData) {
        this.options = {
          tooltip: {
            trigger: "axis",
            backgroundColor: "rgba(255,255,255,0.1)",
            axisPointer: {
              type: "shadow",
              label: {
                show: true,
                backgroundColor: "#7B7DDC",
              },
            },
            textStyle: {
              color: "#fff",
            },
            formatter: function (arg) {
              let str = arg[0].name + "<br/>";
              arg.forEach((item, idx) => {
                str += `${item.marker}${item.seriesName}: `;
                switch (idx) {
                  case 0:
                    str += Number(item.data) + "个";
                    break;
                  case 1:
                    str += Number(item.data).toFixed(2) + "亿人次";
                    break;
                  default:
                    break;
                }
                str += idx === arg.length - 1 ? "" : "<br/>";
              });
              return str;
            },
          },
          legend: {
            data: ["A级旅游景区个数", "接待人次"],
            textStyle: {
              color: "#B4B4B4",
            },
            top: "0%",
          },
          grid: {
            top: "8%",
            left: "12%",
          },
          xAxis: {
            data: newData.category,
            axisLine: {
              lineStyle: {
                color: "#B4B4B4",
              },
            },
            axisTick: {
              show: false,
            },
          },
          yAxis: [
            {
              max: 16000,
              min: 0,
              interval: 2000,
              splitLine: { show: false },
              axisLine: {
                lineStyle: {
                  color: "#B4B4B4",
                },
              },
              axisLabel: {
                formatter: "{value} ",
              },
            },
            {
              max: 70,
              min: 0,
              interval: 10,
              splitLine: { show: false },
              axisLine: {
                lineStyle: {
                  color: "#B4B4B4",
                },
              },
              axisLabel: {
                formatter: "{value} ",
              },
            },
          ],
          series: [
            {
              name: "A级旅游景区个数",
              type: "bar",
              barWidth: 10,
              itemStyle: {
                borderRadius: 5,
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "#956FD4" },
                  { offset: 1, color: "#3EACE5" },
                ]),
              },
              data: newData.numData,
            },
            {
              name: "接待人次",
              type: "bar",
              barWidth: 10,
              yAxisIndex: 1,
              itemStyle: {
                borderRadius: 5,
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "#ff7da1" },
                  { offset: 1, color: "#8378ea" },
                ]),
              },
              data: newData.peopleData,
            },
          ],
        };
      },
      immediate: true,
      deep: true,
    },
  },
};
</script>
